package app;
import info.clearthought.layout.TableLayout;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JColorChooser;
import javax.swing.JFrame;
import javax.swing.JPanel;



/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class ColorChooser extends javax.swing.JDialog {

	{
		//Set Look & Feel
		try {
			javax.swing.UIManager.setLookAndFeel(javax.swing.UIManager.getSystemLookAndFeelClassName());
		} catch(Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	protected JColorChooser jColorChooser1;
	private JPanel jPanel1;
	private JButton cancelar;
	private JButton aceptar;
	Main main;
	

	/**
	* Auto-generated main method to display this JDialog
	*/
	
	
	public ColorChooser(JFrame frame) {
		super(frame);
		initGUI();
	}
	
	

	private void initGUI() {
		try {
			{
				jPanel1 = new JPanel();
				TableLayout jPanel1Layout = new TableLayout(new double[][] {{7.0, TableLayout.FILL, TableLayout.FILL, TableLayout.FILL, TableLayout.FILL, TableLayout.FILL, TableLayout.FILL, 7.0}, {TableLayout.FILL, TableLayout.FILL, 199.0, 7.0, TableLayout.FILL, 7.0}});
				jPanel1Layout.setHGap(5);
				jPanel1Layout.setVGap(5);
				jPanel1.setLayout(jPanel1Layout);
				getContentPane().add(jPanel1, BorderLayout.CENTER);
				jPanel1.setBackground(new java.awt.Color(255,255,255));
				{
					jColorChooser1 = new JColorChooser();
					jPanel1.add(jColorChooser1, "1, 0, 6, 2");
					jColorChooser1.setBackground(new java.awt.Color(255,255,255));
				}
				{
					aceptar = new JButton();
					jPanel1.add(aceptar, "3, 4, c, b");
					aceptar.setText("Aceptar");
					aceptar.setBackground(new java.awt.Color(255,255,255));
					aceptar.setFont(new java.awt.Font("Ubuntu",0,12));
					aceptar.addActionListener(new ActionListener() {
						public void actionPerformed(ActionEvent evt) {
							aceptarActionPerformed(evt);
						}
					});
				}
				{
					cancelar = new JButton();
					jPanel1.add(cancelar, "4, 4, c, b");
					cancelar.setText("Cancelar");
					cancelar.setBackground(new java.awt.Color(255,255,255));
					cancelar.setFont(new java.awt.Font("Ubuntu",0,12));
					cancelar.addActionListener(new ActionListener() {
						public void actionPerformed(ActionEvent evt) {
							cancelarActionPerformed(evt);
						}
					});
				}
			}
			this.setSize(629, 434);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public static String toHexString(Color c) {
		  StringBuilder sb = new StringBuilder('#');

		  if (c.getRed() < 16) sb.append('0');
		  sb.append(Integer.toHexString(c.getRed()));

		  if (c.getGreen() < 16) sb.append('0');
		  sb.append(Integer.toHexString(c.getGreen()));

		  if (c.getBlue() < 16) sb.append('0');
		  sb.append(Integer.toHexString(c.getBlue()));

		  return sb.toString();
		}
	
	private void aceptarActionPerformed(ActionEvent evt) {
		
		Color c= jColorChooser1.getColor();
		main.insertarColor(toHexString(c));
		this.dispose();
	}

	public void conectar(Main m){
		main=m;
	}
	
	private void cancelarActionPerformed(ActionEvent evt) {
		this.dispose();
	}

	

}
